package com.stm.bi.repository.report;

import com.stm.framework.core.util.StringUtil;
import org.springframework.stereotype.Repository;
import com.stm.framework.repository.BaseRepository;
import com.stm.bi.dto.vo.ReportModelVO;
import com.stm.bi.repository.report.mapper.ReportModelMapper;
import com.stm.bi.repository.report.dataobject.ReportModelDO;
import com.stm.bi.dto.query.ReportModelListQry;
import com.stm.bi.dto.query.ReportModelPageQry;
import com.stm.framework.model.CustomizePage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stm.framework.core.tookit.BeanToolkit;
/**
* 报表模型-仓储
*
* @author zhouyuanpeng
* @date 2025-05-22
*/
@Repository
public class ReportModelRepository extends BaseRepository<ReportModelMapper, ReportModelDO, ReportModelVO> {


    /**
    * 报表模型分页查询
    * @param reportModelPageQry 报表模型查询入参对象
    * @return
    */
   public CustomizePage<ReportModelVO> selectPage(ReportModelPageQry reportModelPageQry){
	LambdaQueryWrapper<ReportModelDO> queryWrapper = buildeQueryWrapper(reportModelPageQry);
        IPage<ReportModelDO> page = new Page(reportModelPageQry.getPageNum(),reportModelPageQry.getPageSize());
        page = this.baseMapper.selectPage(page, queryWrapper);
        CustomizePage<ReportModelVO> customizePage = new CustomizePage(BeanToolkit.instance().copyList(page.getRecords(), ReportModelVO.class), page.getSize(), page.getCurrent(), page.getTotal());
        return customizePage;
   }
    /**
    * 报表模型列表查询
    * @param reportModelListQry 报表模型查询入参对象
    * @return
    */
   public List<ReportModelVO> selectList(ReportModelListQry reportModelListQry){
	LambdaQueryWrapper<ReportModelDO> queryWrapper = buildeQueryWrapper(reportModelListQry);
        List<ReportModelDO> records = this.baseMapper.selectList(queryWrapper);
        return BeanToolkit.instance().copyList(records, ReportModelVO.class);
   }
   private LambdaQueryWrapper buildeQueryWrapper(ReportModelListQry reportModelListQry){
	LambdaQueryWrapper<ReportModelDO> queryWrapper = Wrappers.<ReportModelDO>lambdaQuery()
                .like(StringUtil.isNotEmpty(reportModelListQry.getName()),ReportModelDO::getName,reportModelListQry.getName())
                .eq(StringUtil.isNotEmpty(reportModelListQry.getType()),ReportModelDO::getType,reportModelListQry.getType())
                .eq(StringUtil.isNotEmpty(reportModelListQry.getStatus()),ReportModelDO::getStatus,reportModelListQry.getStatus());
        return queryWrapper;
   }

    public ReportModelVO selectByName(String name){
        LambdaQueryWrapper<ReportModelDO> queryWrapper = Wrappers.<ReportModelDO>lambdaQuery()
                .eq(StringUtil.isNotEmpty(name),ReportModelDO::getName,name);
        return BeanToolkit.instance().copy(this.baseMapper.selectOne(queryWrapper), ReportModelVO.class);
    }
}
